package com.soriya.switcher.component

import androidx.annotation.DimenRes
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.dimensionResource
import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.TextUnit
import androidx.compose.ui.unit.sp
import com.soriya.common.R


@Composable
fun dimensionSpResource(@DimenRes id: Int): TextUnit {
    val context = LocalContext.current
    val px = context.resources.getDimension(id) // 保留 sp 语义（返回的是 px，但基于 scaledDensity）
    val scaledDensity = context.resources.displayMetrics.scaledDensity
    val spValue = px / scaledDensity
    return spValue.sp
}

@Composable
fun LargeText(
    text: String,
    color: Color = Color.Unspecified,
    fontStyle: FontStyle? = null,
    fontWeight: FontWeight? = null,
    overflow: TextOverflow = TextOverflow.Clip,
    modifier: Modifier = Modifier
) {
    val size = dimensionSpResource(R.dimen.xsp_22)
    Text(text = text, color = color, fontStyle = fontStyle, fontWeight = fontWeight, overflow = overflow, fontSize = size, modifier = modifier)
}

@Composable
fun MediumText(
    text: String,
    color: Color = Color.Unspecified,
    fontStyle: FontStyle? = null,
    fontWeight: FontWeight? = null,
    overflow: TextOverflow = TextOverflow.Clip,
    modifier: Modifier = Modifier
) {
    val size = dimensionSpResource(R.dimen.xsp_20)
    Text(text = text, color = color, fontStyle = fontStyle, fontWeight = fontWeight, overflow = overflow, fontSize = size, modifier = modifier)
}

@Composable
fun SmallText(
    text: String,
    color: Color = Color.Unspecified,
    fontStyle: FontStyle? = null,
    fontWeight: FontWeight? = null,
    overflow: TextOverflow = TextOverflow.Clip,
    modifier: Modifier = Modifier
) {
    val size = dimensionSpResource(R.dimen.xsp_18)
    Text(text = text, color = color, fontStyle = fontStyle, fontWeight = fontWeight, overflow = overflow, fontSize = size, modifier = modifier)
}

@Composable
fun SmallerText(
    text: String,
    color: Color = Color.Unspecified,
    fontStyle: FontStyle? = null,
    fontWeight: FontWeight? = null,
    overflow: TextOverflow = TextOverflow.Clip,
    modifier: Modifier = Modifier
) {
    val size = dimensionSpResource(R.dimen.xsp_16)
    Text(text = text, color = color, fontStyle = fontStyle, fontWeight = fontWeight, overflow = overflow, fontSize = size, modifier = modifier)
}

@Composable
fun VerySmallerText(
    text: String,
    color: Color = Color.Unspecified,
    fontStyle: FontStyle? = null,
    fontWeight: FontWeight? = null,
    overflow: TextOverflow = TextOverflow.Clip,
    modifier: Modifier = Modifier
) {
    val size = dimensionSpResource(R.dimen.xsp_14)
    Text(text = text, color = color, fontStyle = fontStyle, fontWeight = fontWeight, overflow = overflow, fontSize = size, modifier = modifier)
}